package com.example.controller;

import com.example.domain.ResponseResult;
import com.example.domain.entity.News;
import com.example.service.NewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
@RequestMapping("news")
public class NewsController {
    @Autowired
    private NewsService newsService;
    @GetMapping("clickTop10")
    public ResponseResult clickTop10(){
        List<News> news = newsService.recommendMaxClick();
         return ResponseResult.okResult(news);
    }

    @GetMapping("recommendByTag")
    public ResponseResult recommendByTag(String tag){
        List<News> news = newsService.recommendByTags(tag);
        return ResponseResult.okResult(news);
    }
    @GetMapping("recommendByClickPerence")
    public ResponseResult recmmendByClickPerence(){
        List<News> news = newsService.recommendByClickPercent();
        return ResponseResult.okResult(news);
    }

    @GetMapping("recommendByAll")
    public ResponseResult recommendByAll(String tag){
        int[] news = newsService.recommendByAll(tag);

        // 调用service用id数组请求到新闻信息
        List<News> result = newsService.findById(news);
        return ResponseResult.okResult(result);
    }

    @GetMapping("findById")
    public ResponseResult findById(int[] a){
        List<News> result = newsService.findById(a);
        return ResponseResult.okResult(result);
    }

    @GetMapping("/selectByTag")
    public ResponseResult selectByTag(){return newsService.selectByTag();}

    @GetMapping("/selectByLike")
    public ResponseResult selectByLike(){return newsService.selectByLike();}

    @GetMapping("/selectByClick")
    public ResponseResult selectByClick(){return newsService.selectByClick();}

    @GetMapping("/selectByFinishPercent")
    public ResponseResult selectByFinishPercent(){return newsService.selectByFinishPercent();}

    @GetMapping("/selectAll")
    public ResponseResult selectAll(){return newsService.selectAll();}
}
